3D User Interfaces and 3D App Building Using the Chrome Library Set of Behaviors
Karl Sigiscar
The Chrome Library set of 3D behaviors lets you quickly set up your scene with drag and drop behaviors to adjust rendering parameters. However, you can do much more. You can create a user interface on top of 3D sprites to control behaviors, or you can control a Macromedia Flash movie from the 3D scene. You can also create navigation interfaces using rollover models with associated links, or display a tooltip when rolling over a given model. To perform certain actions, UI behaviors allow you to call handlers on behaviors that are already assigned to the W3D sprite. Combining all of these, you can build more complex projects. The Chrome Library is free and available at the following address: www.chromelib.com
You will start where you left off in the first article dedicated to the Chrome Lib and add interactivity to the scene. You had a car displayed on a booth in the foreground with a screen in the background.
The mesh and textures of the car W3D files in this article were created by Stephen Magnardi. You can purchase the car W3D files used in this article from TurboSquid.com (search keyword: signum). However, you can use the Chrome Library behaviors on most any W3D file. Turbo Squid also has free W3D files that you can use to experiment with the Chrome Library behaviors. The W3D file of the car, wheels, and booth is made up of 21,603 polygons. Most textures are 256 x 256 pixels in size. Some textures are 512 x 512.
Requirements
To complete this tutorial you will need to install the following software and files:
Director MX 2004
Tutorials and sample files:
Purchase and download the W3D files from TurboSquid.com (search keyword: signum)
Setting Up the Texture Render Format
In the first article, you learned how to set up the texture render format to 32 bits so the alpha channel gradient of the headlights’ rays render properly. You also learned how to remove them from the scene. This time, you will leave the headlights visible.
Figure 1. The Texture Render Format behavior
Be sure the texture render format is set to 32 bit (RGBA8888) using the Texture Render Format behavior (see the first article). This will be important for providing a clean rendering on the overlay textures later on in the project.
Figure 2. The jaggy, non–anti-aliased scene.
Setting Up Hardware Anti-Aliasing (FSAA)
If your 3D graphics card is Direct X compliant and is capable of hardware anti-aliasing (Full Screen Anti-Aliasing), you can activate it on your Shockwave 3D scene using the Chrome Lib. Even entry-level graphics cards such as the ATI Radeon 7000 are now endowed with FSAA under DirectX 7, so you can easily benefit from this feature. However, hardware anti-aliasing is only available with Director MX 2004 and version 10 of Macromedia Shockwave Player.
Figure 3. The Anti-Aliasing behavior
-
Drag and drop the Anti-Aliasing behavior from the Chrome Lib onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:
- Check the Hardware Anti-Aliasing box. Click OK.
-
Click the Play button in the Control panel or press Enter to start the movie. The scene is now anti-aliased and looks much better.
Figure 4. The Anti-Aliasing Parameters dialog box
Figure 5. The smooth anti-aliased scene.
Not only does hardware anti-aliasing improve rendering quality—it doesn't slow rendering speed as is the case with software anti-aliasing. For hardware anti-aliasing, the graphics card GPU (Graphics Processing Unit) wires this function. For software anti-aliasing, it is the computer's CPU that does all the required computation, hence the slowdown.
Setting Up the Shader Blend Level for Reflection
The car body has been given an environment map by the graphic artist in 3DS Max. However, with the current parameters, the car body is way too shiny. You need to tweak the shader blend level to get the visual result you want. The blend level indicates how much the map is blended with the underlying diffuse color.
Figure 6. The Shader Blend behavior
-
Drag and drop the Shader Blend behavior from the Chrome Library onto the W3D sprite. You can do this either on the Stage or in the Score. The following dialog box appears:
Figure 7. The Shader Blend dialog box
- Select the Body Model and set the Shader Blend to 64%.
- Click OK.
- Click the Play button in the Control panel or press Enter to start the movie. The car body still reflects the reflection map, but it looks more realistic as it is less shiny.
Figure 8. The car with the correct shader blend level
Opening and Closing the Movable Parts of the Car
You want the user to be able to open and close the movable parts of the car, namely the hood, the trunk, the doors, and the seats. This is simple as you only have to care about the rotation on one axis. The pivot point of each separate model of the car has already been set in 3DS Max, so all movable parts rotate correctly about their axes.
| Hood | Target Y axis rotation : 50.00 |
|---|---|
| Trunk | Target Y axis rotation : -65.00 |
| Front seat left | Target Y axis rotation : 20.00 |
| Front seat right | Target Y axis rotation : 20.00 |
| Front door left | Target Z axis rotation : -75.00 |
| Front door right | Target Z axis rotation : 75.00 |
| Rear door left | Target Z axis rotation : -75.00 |
| Rear door right | Target Z axis rotation : 75.00 |
-
Drag and drop the Open/Close Model behavior from the Chrome Lib onto the W3D sprite, either on the Stage or in the Score.
Figure 9. The Open/Close Model behavior
The following dialog box appears:
Figure 10. The Open/Close Model parameters dialog box
- Select the model you want to manipulate.
-
Make sure the Copy Position parameter is checked and enter the correct rotation on the relevant axis, for example, 20 degrees on the Y axis for the Front Seat Right model.
If the sliders are too touchy for you, enter precise values in the behavior tab of the Property inspector:
Figure 11. The Property inspector showing the Open/Close model behavior
You must create an instance of the behavior for each model you want to open/close. In this case, you would have to drag and drop the same behavior eight times, each time with a different set of parameters (that is, a different model, axis, and rotation value).
Click the Play button in the Control panel or press Enter to start the movie. Click the hood, the trunk, the doors, or the seats, and they open in a smooth, progressive way. Click them again, and they will close in the same way. You can interrupt the opening or closing of a movable part while it rotates by clicking it, and it will immediately start rotating in the opposite direction. The rotation boundaries on the axis are defined by the original rotation and by the set target rotation behavior.
Figure 12. The car with the hood and the driver door open
Creating a UI on Top of the 3D Scene
You will use the booth screen to display photographs of Paris and London to create ambiance for the booth. If you have ever been to a motor show, you know car makers always try to create ambiance for their booths. You want the user to be able to switch between photographs by clicking overlay buttons.
Import the nine bitmap cast members for full-size pictures and nine smaller ones for thumbnails. These should be imported into the internal cast and are included in the sample files download linked at the beginning of this article.
The 3D graphic artist created a shader called Booth Screen in the scene so you can display pictures onto the screen. It has an emissive color already set to white (RGB 255, 255, 255) in 3DS Max, so it looks realistic when you display pictures or videos on it.
For each photo button, you will apply two behaviors, the Environmental Mapping and Overlay Button UI behaviors, as shown below.
Figure 13a. The Environment Mapping behavior
Figure 13b. The Overlay Button UI behavior
-
Drag and drop the Environment Mapping behavior from the Chrome Library onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:
Figure 14. The Environment Mapping Parameters dialog box
- Select Booth Screen as the shader to affect .
- Uncheck Affect all shaders.
- Select the Booth Screen model.
- Select the full-size picture you want to display on the booth screen for the bitmap parameter.
- Select texture as Mapping type.
- Click OK.
-
Drag and drop the Overlay Button UI behavior from the Chrome Lib onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:
Figure 15. The Overlay Button UI parameters dialog box
- Enter the relevant X and Y coordinates in pixels for the button position on top of the 3D scene. For instance, you want to have the buttons displayed at the bottom left corner of the scene.
- As you do not have several different bitmaps for the normal, pressed, rollover, and selected states, select the same thumbnail bitmap for all four states. This is mandatory. The thumbnail bitmap must match the full-sized image you selected in the first behavior.
- Uncheck Button Group as you do not want a radio button behavior and you are not creating a navigation interface, only click buttons.
- Select the W3D Sprite number (that is, the number of the sprite channel displaying the W3D cast member).
- Enter the Behavior number of the previously created behavior (the Environment Mapping behavior). You need this to tell Director what behavior this button will control. You can find a behavior number by looking at the behavior list in the Behavior tab of the Property inspector.
- Enter
beginSprite()as the Handler call. - Click OK.
Repeat these two steps for the nine photos.
Here is the behavior list of the W3D sprite in the Behavior inspector. As you can see, there are now quite a few behaviors assigned to the W3D sprite:
Figure 16. The Behavior inspector
Click the Play button in the Control panel or press Enter to start the movie. The nine buttons appear at the bottom left corner on top of the 3D scene. By default, the first photo displayed on the screen is the one pointed to by the last assigned Environment Mapping behavior. Click any button, and the corresponding picture will display on the booth screen in the background.
Figure 17. The car with the nine overlay buttons displayed
If you would like to have no picture displayed when the movie starts, use a blank bitmap as the thumbnail and a full-size image for the last button. This way, the first picture displayed on the booth screen will be blank (that is, white, beige, gray, or black). Also, when the user wants to disable picture viewing, he/she will be able to click the last button to reset the display. The nobackground.gif image is included in the sample files in the bitmaps/pictures folder (together with the nine photos) so you can experiment with this idea.
Changing the Camera
The graphic artist created and positioned a number of cameras in 3DS Max. You want the user to be able to switch from one view to the previous or next one with a camera travelling. For this purpose, you will use the Change Camera behavior in order to switch views, and you will use the Overlay Button UI to create the two necessary buttons to trigger the travelling.
Figure 18. The Change Camera behavior
Figure 19. The Overlay Button UI behavior
- In the internal cast, import two 32-bit bitmap cast members with alpha channel depicting arrows, one pointing left, the other pointing right: btn_previous_camera and btn_next_camera. They are transparent so you can see the shape of them and see through. Both of these files are included in the sample files linked from the beginning of this article.
- Drag and drop the Change Camera behavior from the Chrome Library onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:
- Make sure the Cut parameter is unchecked and press OK.
-
Drag and drop the Overlay Button UI behavior from the Chrome Library onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:
Figure 21. The Overlay Button parameters dialog box
- Enter the relevant X and Y coordinates in pixels for the button position on top of the 3D scene. You want to have the two buttons displayed at the bottom right corner of the scene.
- As you do not have several different bitmaps for the normal, pressed, rollover and selected states, select the same btn_previous_camera bitmap cast member for all four states. This is mandatory.
- Uncheck Button Group, as you do not want a radio button behavior and you are not creating a navigation interface, only click buttons.
- Select the W3D Sprite number (that is, the number of the sprite channel displaying the W3D cast member).
- Enter the Behavior number of the previously created behavior (such as the Change Camera behavior). You need this to tell Director what behavior this button will control. You can find a behavior number by looking at the behavior list in the Behavior tab of the Property inspector.
- Enter
previousCamera()as the Handler call. - Click OK.
-
Drag and drop the Overlay Button UI behavior from the Chrome Lib onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:
Figure 22. The Overlay Button parameters dialog box
- Enter the relevant X and Y coordinates in pixels for the button position on top of the 3D scene. You want to have the two buttons displayed at the bottom right corner of the scene.
- As you do not have several different bitmaps for the normal, pressed, rollover, and selected states, select the same btn_next_camera bitmap cast member for all four states. This is mandatory.
- Uncheck Button Group as you do not want a radio button behavior and you are not creating a navigation interface but just click buttons .
- Select the W3D Sprite number ( that is, the number of the sprite channel displaying the W3D cast member).
- Enter the Behavior number of the previously created behavior (such as the Change Camera behavior). You need this to tell Director what behavior this button will control. You can know a behavior number by looking at the behavior list in the behavior tab of the Property inspector.
- Enter
nextCamera()as the Handler call. - Press OK.
Figure 20. The Change Camera parameters dialog box
Click the Play button in the Control panel or press Enter to start the movie. The previous and next camera buttons appear at the bottom right corner on top of the 3D scene. Click the next camera button (the right arrow). The camera travels smoothly to the next view (camera) present in the scene. Click the previous button (the left arrow). The camera travels smoothly to the previous view (camera) present in the scene. You can interrupt a travelling at anytime by clicking any of the two buttons to start travelling to another camera.
Figure 23. The camera travelling to another view
Here is the internal cast upon completion of the project:
Figure 24. The internal cast
Creating a 3D Navigation System for a Website
In this next section, you will use the W3D file of a town that is included in the sample files linked from the beginning of this article. You want the user to be able to click a building to display a corresponding web page in a frame located in the lower part of the page.
- Create a new movie in Macromedia Director.
- Edit the Movie Properties in the Property inspector (Movie tab) and give the stage a size of 760 pixels in width and 300 in height.
- Drag and drop the town W3D cast member directly onto the Stage or onto the Score to have it centered automatically.
-
Resize the W3D sprite directly on the Stage or in the Property inspector (Sprite tab) so it fits the Stage size (760 x 300).
Figure 25. The town scene stage
In Macromedia Dreamweaver or in a text editor, create an HTML document with the following HTML code:
<FRAMESET ROWS="300, *" border=0 scroll=no> <FRAME NAME="nav" SRC="sw3d_nav.htm" scrolling=no> <FRAME NAME="display" SRC="default.htm"> </FRAMESET>
The first frame, nav, will display the navigation interface created with Shockwave 3D and will include the <OBJECT> and <EMBED> tag output by Director when publishing the movie. The second frame, whose name is display, will be the target frame in which the pages will be displayed.
- Save the frameset HTML document as index.html.
- Create a new page and name it default.htm. It will be the first page shown in the display frame.
- Create yet another page and enter some text. Save it as small_pyramid.html.
-
In Macromedia Director, drag and drop the Go to URL with Rollover behavior onto the W3D sprite.
Figure 26. The Go to URL with Rollover behavior
The following dialog box appears:
Figure 27. The Go to URL with Rollover parameters dialog box
- Select the small pyramid model and enter the URL to the corresponding page: small_pyramid.html.
- Select _targetname as Target and enter display as the target name (the name of the frame where you want to display pages).
- Create several instances of the Go to URL with Rollover behavior. Drag and drop it several times onto the W3D sprite, each time selecting a different model and entering a URL to another HTML document. But always specify display as the target frame.
-
Edit the Publish Settings in the File menu of the movie. The following dialog box appears:
Figure 28. The formats tab of the Publish Settings dialog box
- Enter the name sw3d_nav.htm for the HTML file. This is important as the frameset document is already pointing to this file.
- In Windows Explorer or the Macintosh Finder, double-click the index.html file to launch the browser as shown in figure 29 below.
Figure 29. The project as viewed in Internet Explorer
When you roll the mouse over the small pyramid, it highlights in yellow, and the mouse cursor changes to a hand. Click the small pyramid, and the link is displayed in the display frame in the lower part the page as shown in figure 30 below.
Figure 30. The small pyramid.htm file shown in the display frame.
Controlling Macromedia Flash from Shockwave 3D
Now you will do almost the same thing, but in a different way. Instead of displaying an HTML document when a user clicks a model, you will have the playhead jump to a frame in an embedded Macromedia Flash movie. The FLA and SWF files of this tutorial are available in the sample files linked from the beginning of this article.
Note: You need Macromedia Flash MX 2004 to complete this section of the article. Download the trial, or purchase the full version.
- Start with the existing movie and select Save As to create a new one. Give it a file name of your choosing.
- Edit the Movie properties in the Property inspector (Movie tab). Give the Stage a size of 760 pixels in width and 600 pixels in height.
Next, you will create several different labelled keyframes. The Macromedia Flash playhead will jump to a keyframe when the mouse rolls over a given model. Another way would be to create different scenes with each a different name.
- In Macromedia Flash, create a new Flash movie.
- In the Property inspector, enter the label default for the current frame.
- Position the playhead on frame 20 and press F6 to create an empty keyframe.
In the Property tab, enter the label small pyramid.
Figure 31. The Flash Property inspector
Figure 32. The Flash Timeline with the small pyramid frame label.
- Enter some relevant text on the Stage, such as small pyramid building. You could also import a picture and improve the layout or add a display effect. But keep it simple for now.
- Export the SWF file.
In Macromedia Director, import the SWF file you just created.
Figure 33. The Import files dialog box
-
Drag and drop the SWF file from the internal cast onto the Stage, next to the W3D scene. You can tweak its position in the Tweak window or in the Sprite tab of the Property inspector.
If you chose to link to the SWF file on importing (Media > Link to External File), you can access Macromedia Flash from within Director by clicking Launch External Editor in the contextual menu of the Flash cast member in the internal cast. This lets you modify it.
Figure 34. The Launch External Editor menu option
-
Press Done in Macromedia Flash when you have finished altering the SWF file.
Figure 35. Click Done to return to Director
Using these steps, you can move back and forth between Macromedia Flash and Director until you are satisfied with the result.
Figure 36. The Flash Control from Model behavior
-
In Macromedia Director, drag and drop the Flash Control from Model behavior from the Chrome Library onto the W3D sprite, either on the Stage or in the Score. The following dialog box appears:
Figure 37. The Flash Control from Model Parameters dialog box
- Select Small Pyramid for the Model parameter.
- Select the relevant Flash Sprite number.
- Enter the frame label the playhead will jump to: small pyramid.
- By default, the 3D model rollover color is yellow. Click OK.
- Click the Play button in the Control panel or press Enter to start the movie.
When you roll the mouse over the small pyramid, it highlights in yellow and the mouse cursor changes to a hand. Click the small pyramid and the playhead of the Flash sprite jumps to the small pyramid label, displaying the contextual information about this building.
Figure 38. The completed project
Here is the internal cast upon completion of the project:
Figure 39. The internal cast upon completion of the project
Afterword
As it is, the town 3D navigation system is not much better than a page made with a simple HTML table containing clickable rollover images. However, imagine you combine the 3D navigation system with the camera travelling interface you created on top of the car scene in the first part of the article (with the previous and next camera arrow buttons). Users would then be able to travel the city from one district to another. Each district would have a number of active buildings, and users would be able to roll the mouse over and click buildings while travelling. You could then turn this into a powerful navigation system.
This is definitely something you could not do with a simple HTML page. The freely downloadable town W3D has a number of preset cameras, so you can experiment with this idea. The btn_previous_camera.png and btn_next_camera.png bitmaps are available in the sample files in the bitmaps/buttons folder.
Conclusion
The Chrome Library provides you with all the necessary building blocks to create a 3D User Interface on top of the scene, a truly interactive 3D application, or a 3D navigation system for a website. By creating several instances of the same behavior (such as the Overlay Button UI) and combining the different behaviors, you can create powerful rich media projects in no time.